# 1）进入然知系统，跳转到该页面后操作
# 页面的加载全部使用显式等待
# 输入正确的成员信息，点击保存，跳转到如下页面代表保存成功，
# 将该页面截图保存

import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Edge()
driver.get("http://127.0.0.1/ranzhi/www/")
time.sleep(3)

# 用户名密码
driver.find_element("xpath",'//*[@id="account"]').send_keys("admin")
driver.find_element("xpath",'//*[@id="password"]').send_keys("123456")
# 点击登录
driver.find_element("xpath",'//*[@id="submit"]').click()
time.sleep(2)
# 显性等待
locator1 = ("xpath",'//*[@id="s-menu-superadmin"]/button/i')
input1 = WebDriverWait(driver,5,0.5).until(expected_conditions.presence_of_element_located(locator1))
# 点击后台管理
driver.find_element("xpath",'//*[@id="s-menu-superadmin"]/button/i').click()

# 切换到iframe
locator2 = ("id","iframe-superadmin")
input2 = WebDriverWait(driver,5,0.5).until(expected_conditions.presence_of_element_located(locator))
# 定位到iframe
iframe = driver.find_element("id","iframe-superadmin")
driver.switch_to.frame(iframe)
# 显性等待
locator3 = ("class name","shortcut.user")
input3 = WebDriverWait(driver,5,0.5).until(expected_conditions.presence_of_element_located(locator1))
# 点击添加成员
driver.find_element("class name","shortcut.user").click()
# 用户名
driver.find_element("id","account").send_keys("123456789")
# 真实姓名
driver.find_element("id","realname").send_keys("罗铖")
# 性别
#部门
bm = driver.find_element("id","dept")
    # 强转为select对象
s = Select(bm)
    # 获取所有的下拉选项的对象
ls = s.options
lstext = []
for i in ls:
    lstext.append(i.text)
    # 选中
s.select_by_visible_text(lstext[2])
# 角色
js = driver.find_element("id","role")
    # 强转为select对象
s1 = Select(js)
    # 获取所有的下拉选项的对象
ls1 = s1.options
lstext1 = []
for j in ls1:
    lstext1.append(j.text)
    # 选中
s1.select_by_visible_text(lstext1[4])
# 密码
driver.find_element("id","password1").send_keys("123456")
# 请重复密码
driver.find_element("id","password2").send_keys("123456")
# 邮箱
driver.find_element("id","email").send_keys("2459496850@qq.com")
# 保存
driver.find_element("id","submit").click()
time.sleep(5)
locator4 = ("id","submit")
input4 = WebDriverWait(driver,5,0.5).until(expected_conditions.presence_of_element_located(locator1))
# 页面截图
# timestr = time.strftime("%Y-%m-%d_%H-%M-%S",time.localtime())
# driver.get_screenshot_as_file(f"d:\\chengyuan{timestr}.png")
# time.sleep(3)

# 2）总结抄写：
# 显式等待和隐式等待的区别
# 你对浏览器都进行过什么操作，分别是什么方法
# 如何选择页面组件的定位
# XPath定位元素时，绝对路径和相对路径有什么区别？
# 如果从下拉框中选中一个数据
# 如何使用Selenium上传文件？